home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 3 / 003.d81 / base converter (.txt) < prev    next >
Commodore BASIC  |  2022-08-26  |  2KB  |  94 lines

  1. 50 sp$=" "
  2. 60 foras=0to38:sp$=sp$+" ":next
  3. 90 print"[147]":poke53281,7:poke53280,6:poke783,peek(783)and254
  4. 100 poke781,2:poke782,11:sys65520:print" base conversion "
  5. 110 :
  6. 120 :
  7. 130 ifp=1then150
  8. 140 rem       fork=0to2200:print;:next
  9. 150 n$="0123456789abcdefghijklmnopqrstuvwxyz"
  10. 160 poke781,6:poke782,0:sys65520
  11. 162 forcl=1to18:printsp$;:next
  12. 170 m=len(n$)
  13. 180 poke781,5:poke782,9:sys65520
  14. 190 print"use base ten notation"
  15. 200 poke781,8:poke782,0:sys65520
  16. 210 print"convert from"
  17. 220 print"base ";
  18. 230 input"      [157][157][157][157][157][157]";b1$
  19. 240 ifb1$=chr$(.)then160
  20. 250 ifb1$="0"then160
  21. 260 rem   test base number 1
  22. 270 b1=val(b1$)
  23. 280 ifb1>1 and b1<37 then320
  24. 290 poke781,22:poke782,1
  25. 300 sys65520:print"base 2 through 36 only.  select again"
  26. 310 goto180
  27. 320 poke781,8:poke782,26:sys65520:
  28. 330 print"converted to"
  29. 340 poke781,10:sys65520:print"base ";
  30. 350 input"     [157][157][157][157][157]";b2$
  31. 360 ifb2$="0"then160
  32. 370 ifb2$=""then160
  33. 380 rem   test base number 2
  34. 390 b2=val(b2$)
  35. 400 ifb2>1 and b2<m then445
  36. 410 poke781,22:poke782,1:sys65520:print"base 2 through 36 only.  select again"
  37. 430 goto320
  38. 445 rem     input number
  39. 450 poke781,11:poke782,1:sys65520:forcl=1to13:printsp$;:next
  40. 460 poke781,12:poke782,0:sys65520:print"value in base"b1"to convert";
  41. 470 input"    [157][157][157][157]";s$
  42. 475 rem     test input
  43. 480 l=len(s$)
  44. 490 ifs$="0"ors$=""then450
  45. 500 fork=1tol:a$=mid$(s$,k,1)
  46. 510 ifa$="."thenpoke781,12:sys65520:print"whole numbers only":forj=1to30000:next:goto450
  47. 530 next
  48. 540 q=0
  49. 550 fork=1tol
  50. 560 forj=1tob1
  51. 570 ifmid$(s$,k,1)=mid$(n$,j,1)thenq=q+1
  52. 580 nextj,k
  53. 590 ifl>qthengosub980:goto450
  54. 600 rem    first conver to base 10
  55. 610 y1=y1+1
  56. 620 poke781,19:poke782,10:sys65520:print"";mg$(y1)
  57. 640 ify1=10theny1=0
  58. 650 ifl<=7then670
  59. 660 poke781,23:poke782,2:sys65520:print"answer may be wrong, number too long[146]";
  60. 670 fork=1to500*l:nextk
  61. 675 rem     the heart of the program
  62. 680 d=0
  63. 690 fork=1tol
  64. 700 forj=1tob1
  65. 710 ifmid$(n$,j,1)<>mid$(s$,k,1)then730
  66. 720 d=d+int(((j-1)*(b1^(l-k))+.5))
  67. 730 nextj,k
  68. 750 rem   convert for output
  69. 760 a$=" "
  70. 770 x=int(((d/b2)-int(d/b2))*b2+1.5)
  71. 780 a$=mid$(n$,x,1)+a$
  72. 790 d=int(d/b2)
  73. 800 ifd>0then770
  74. 810 rem    print results
  75. 820 poke781,15:poke782,0:sys65520:prints$;" ";:poke781,15:poke782,30:sys65520
  76. 825 print"base ";b1
  77. 830 printa$;" ":poke781,16:poke782,30:sys65520:print"base ";b2
  78. 840 print:poke781,18:poke782,0:sys65520
  79. 850 print"<return> to continue":print"<c> to change base":print"<x> to exit"
  80. 860 poke198,0:wait198,1:getq$:ifq$<>chr$(13) and q$<>"c" and q$<>"x"then860
  81. 870 if q$=chr$(13)then450
  82. 880 if q$="x"then920
  83. 890 p=1:goto90
  84. 910 stop   rem   the end
  85. 920 print"[147]load"chr$(34)"payload"chr$(34)",8":print"run":poke631,13:poke632,13
  86. 930 poke198,2:end
  87. 980 poke781,12:sys65520:forcl=1to6:printsp$;:next
  88. 990 poke783,peek(783)and254:poke781,12:poke782,12:sys65520:print"inproper input[146]"
  89. 1000 fork=1to2000:next:return
  90. 2000 rem          written
  91. 2010 rem             by
  92. 2020 rem        bob scofield
  93. 2030 rem
  94.